<?php
/**
 * Responses.php
 * @author 瀚海浪亭
 * @email  1171672036@qq.com
 * @date   2021/4/17
 */

namespace Tools;


class Responses
{
    /**
     * 组装json数据
     *
     * @param int $code 状态码
     * @param string $message 消息
     * @param array $data 数据
     * @param array $pages 分页
     * @return \think\response\Json
     */
    public static function data($code, $message, $data = [], $pages = [])
    {
        $responses            = [];
        $responses['code']    = $code;
        $responses['message'] = $message;
        if (!empty($data)) {
            $responses['data'] = $data;
        }
        if (!empty($pages)) {
            $responses['pages'] = $pages;
        }

        return json($responses, 200);
    }
}